	package com.sp.scmdb.action;

import java.io.InputStream;
import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.sp.scmdb.bean.RealTimeLabelIOBeanBean;
import com.sp.scmdb.bean.UserBean;
import com.sp.scmdb.common.CommonParamter;
import com.sp.scmdb.common.action.BaseAction;
import com.sp.scmdb.entity.Department;
import com.sp.scmdb.entity.Duty;
import com.sp.scmdb.entity.WorkType;
import com.sp.scmdb.service.DepartmentService;
import com.sp.scmdb.service.DutyService;
import com.sp.scmdb.service.LabelIOService;
import com.sp.scmdb.service.WorkTypeService;

@Controller("realTimeLabelIOAction")
@Scope("prototype")
public class RealTimeLabelIOAction extends BaseAction<RealTimeLabelIOBeanBean> {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private static Log log = LogFactory.getLog(RealTimeLabelIOAction.class);
	private LabelIOService labelIOService;
	private DepartmentService departmentService;
	private DutyService dutyService;
	private WorkTypeService workTypeService;
	private InputStream excelStream;
	private String fileName;

	public InputStream getExcelStream() {
		return excelStream;
	}

	public void setExcelStream(InputStream excelStream) {
		this.excelStream = excelStream;
	}

	public String getFileName() {
		return fileName;
	}

	public void setFileName(String fileName) {
		this.fileName = fileName;
	}

	@Autowired
	public void setDepartmentService(DepartmentService departmentService) {
		this.departmentService = departmentService;
	}

	@Autowired
	public void setDutyService(DutyService dutyService) {
		this.dutyService = dutyService;
	}

	@Autowired
	public void setWorkTypeService(WorkTypeService workTypeService) {
		this.workTypeService = workTypeService;
	}

	@Autowired
	public void setLabelIOService(LabelIOService labelIOService) {
		this.labelIOService = labelIOService;
	}
	public String initLabelIO() {
		try {
			session.remove("labelIOBean");
			UserBean user = (UserBean) session.get("user");
			List<Department> depList = departmentService.queryAll(user);
			List<Duty> dutyList = dutyService.queryAll();
			List<WorkType> workTypeList = workTypeService.queryAll();
			request.setAttribute("depList", depList);
			request.setAttribute("dutyList", dutyList);
			request.setAttribute("workTypeList", workTypeList);
			return SUCCESS;
		} catch (Exception e) {
			log.error("init labelIO failed! reason:" + e.getMessage());
			return "fail";
		}
	}
	@SuppressWarnings("unchecked")
	public String findAll() {
		try{
			RealTimeLabelIOBeanBean labelIOBean= null;
			if(StringUtils.isNotEmpty(pageName)){
				labelIOBean=(RealTimeLabelIOBeanBean)session.get("realTimeLabelIOBean");
			}
			UserBean user =(UserBean)session.get("user");
			List<Department> depList=departmentService.queryAll(user);
			List<Duty> dutyList=dutyService.queryAll();
			List<WorkType> workTypeList= workTypeService.queryAll();
			request.setAttribute("depList", depList);
			request.setAttribute("dutyList", dutyList);
			request.setAttribute("workTypeList", workTypeList);
			if(StringUtils.isNotEmpty(entity.getInTime())&&StringUtils.isNotEmpty(entity.getOutTime())){
				setEntity(labelIOService.getRealTimeLabelIOAll(entity, labelIOBean, user));
				session.put("labelIOBean", entity);
			}else {
				session.remove("labelIOBean");
				messageSession(CommonParamter.CHECK_FLG, "请输入查询时间段");
			}
			session.put("realTimeLabelIOBean", entity);
			return SUCCESS;
		}catch (Exception e) {
			log.error("get labelIO failed! reason:" + e.getMessage());
			return "fail";
		}
			
		
	}
}
